define(function(require, exports, module){
	function Loading(o) {
		o = o || {};

		o = $.extend({
			"container" : null
		}, o);

		if (o.container == null) {
			throw new Error("容器不能没有");
		}

		this.width = o.container.outerWidth();
		this.height = o.container.outerHeight();

		var posContainer = o.container.offset();
		this.left = posContainer.left;
		this.top = posContainer.top;

		this.option = o;
		this.init();
	}

	Loading.prototype = {
		init: function(){
			var _this = this;

			var loadingDiv = $("<div></div>");
			loadingDiv.css({
				width: this.width + 'px',
				height: this.height + 'px',
				top: this.top + 'px',
				left: this.left + 'px',
				position: 'absolute',
				backgroundColor: 'rgba(0, 0, 0, 0)',
				display: 'none'
			});

			var img = $("<img src='images/loading.png' class='loading'/>");

			img.on("load", function(){
				var w = this.width;
				var h = this.height;
				$(this).css({
					marginLeft: (_this.width - w) / 2,
					marginTop: (_this.height - h) / 2
				});
			});

			loadingDiv.append(img);
			$("body").append(loadingDiv);

			this.loadingDiv = loadingDiv;
		},
		start: function(){
			this.loadingDiv.show();
		},
		stop: function(){
			this.loadingDiv.hide();
		}
	};

	exports.Loading = Loading;
});